﻿using Appliaction.Dto.DB;
using Appliaction.IAppServices.DB;
using AutoMapper;
using Domain.Entitys.DB;
using Domain.IRepositorys.DB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Appliaction.AppServices.DB
{
    public class Db_AttachmentService : IDb_AttachmentService
    {
        private readonly IDb_AttachmentRepository db_AttachmentRepository;
        private readonly IMapper mapper;

        public Db_AttachmentService(IDb_AttachmentRepository db_AttachmentRepository, IMapper mapper)
        {
            this.db_AttachmentRepository = db_AttachmentRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 添加文件信息
        /// </summary>
        /// <param name="attachmentFileAddDto"></param>
        /// <returns></returns>
        public async Task<int> AttachmetAddAsync(Db_AttachmentFileAddDto attachmentFileAddDto)
        {
            Db_Attachment db_Attachment = mapper.Map<Db_Attachment>(attachmentFileAddDto);
            return await db_AttachmentRepository.AttachmetAddAsync(db_Attachment);
        }

        /// <summary>
        /// 根据编号删除对应公共附件
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public int Attachmetdel(string code)
        {
            return db_AttachmentRepository.Attachmetdel(code);
        }

        /// <summary>
        /// 根据编号查询对应的附件信息
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public async Task<List<Db_Attachment>> GetDb_AttachmentsAsync(string code)
        {
            return await db_AttachmentRepository.GetDb_AttachmentsAsync(code);
        }
    }
}
